// pages/lifeService/index.js
const app = getApp();
var topOpacity = 0;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 组件参数设置，传递到组件
    defaultData: {
      title: "生活服务", // 导航栏标题
      showHome: false, //是否显示回到首页按钮
      showBack: true, //是否显示返回按钮
      showLogo: false, //是否显示logo
      bgColor: 'transparent',
      goUrl: '/pages/index/index'
    },
    baseUrl: app.baseUrl,
    version: app.globalData.version,
    navBarHeight: app.globalData.navBarHeight,

    shareTitle: '',
    shareImg: '',
    mySf: ''
  },
  onPageScroll(t) {
    if (t.scrollTop < 40) {
      topOpacity = 0
      if (this.data.topOpacity != 0) {
        this.setData({
          topOpacity: 0
        })
      }
    } else if (t.scrollTop >= 40) {
      if (topOpacity <= 1) {
        topOpacity = t.scrollTop / 100 - .4
      } else {
        topOpacity = 1
      }
      if (topOpacity <= 1) {
        this.setData({
          topOpacity: topOpacity
        })
      }
    }
  },
  //跳转家宴
  goJy() {

    /*app.showTip('7月20日上线 敬请期待');
    return;*/

    //判断身份
    if (this.data.mySf == '游客') {
      //app.showTip('您还未认证业主身份,请前往个人中心进行认证');
      //return;
      wx.navigateTo({
        url: '/pages/familyFeast/menu?mySf=游客'
      });
      return;
    }

    //跳转家宴首页
    wx.navigateTo({
      url: '/pages/familyFeast/index'
    });
  },
  //物业服务
  goWy() {
    //判断身份
    if (this.data.mySf == '游客') {
      app.showTip('您还未认证业主身份,请前往个人中心进行认证');
      return;
    }
    wx.navigateTo({
      url: '/pages/lifeService/managementFee/menu',
    })
  },
  //问卷调查
  goQuestion() {
    wx.navigateTo({
      url: '/pages/lifeService/question/index',
    })
  },
  //权益中心
  goEquity() {
    wx.navigateTo({
      url: '/pages/equity/index',
    })
  },
  //跳转食堂菜谱
  goCanteen() {
    wx.navigateTo({
      url: '/pages/lifeService/canteen/index'
    });
  },
  //跳转生活通讯录
  goAddressBook() {
    wx.navigateTo({
      url: '/pages/lifeService/addressBook/index'
    });
  },
  //跳转美食地图
  goFoodMap() {
    wx.navigateTo({
      url: '/pages/lifeService/foodMap/map'
    });
  },
  goBusiness() {
    //跳转麓商家
    wx.navigateTo({
      url: '/pages/business/index'
    });
  },
  goSpace() {
    // 空间预约
    if (this.data.mySf == '游客') {
      app.showTip('您还未认证业主身份,请前往个人中心进行认证');
      return;
    }
    wx.navigateTo({
      url: '/pages/orderCenter/siteOrder/index'
    });
  },
  //跳转快递预约
  goDelivery() {
    // 快递预约
    // wx.showToast({
    //   title: '10月10日即将上线',
    //   icon:'none'
    // })
    if (this.data.mySf == '游客') {
      app.showTip('您还未认证业主身份,请前往个人中心进行认证');
      return;
    }
    wx.navigateTo({
      url: '/pages/expressReservation/infor/index',
    });
  },
  lost() {
    wx.navigateTo({
      url: '/pages/orderCenter/lost/index'
    })
  },
  goPicMenu1() {
    wx.redirectTo({
      url: '/pages/lifeService/managementFee/lmj',
    })
  },
  goPicMenu2() {
    wx.redirectTo({
      url: '/pages/lifeService/managementFee/lxj',
    })
  },

  go1() {
    //增加点击量
    this.addClickNumber();
    wx.navigateToMiniProgram({
      appId: 'wx09df719a551e8820',
      path: 'property/pages/payCost/home/home',
      //develop开发版；trial体验版；release正式版
      envVersion: 'release',
      success(res) {
        // 打开成功
        console.log("跳转小程序成功！", res);
      }
    })
    // wx.navigateTo({
    //   url: '/pages/lifeService/managementFee/index',
    // })
  },
  go2() {
    // wx.navigateToMiniProgram({
    //   appId: 'wx09df719a551e8820',
    //   path: 'property/pages/reportRepair/register/register',
    //   //develop开发版；trial体验版；release正式版
    //   envVersion: 'release',
    //   success(res) {
    //     // 打开成功
    //     console.log("跳转小程序成功！", res);
    //   }
    // })
    //增加点击量
    this.addClickNumber();
    wx.redirectTo({
      url: '/pages/lifeService/repairReport/index',
    })
  },
  go3() {
    // wx.navigateToMiniProgram({
    //   appId: 'wx09df719a551e8820',
    //   path: 'property/pages/invite/inviteVisitors/inviteVisitors',
    //   //develop开发版；trial体验版；release正式版
    //   envVersion: 'release',
    //   success(res) {
    //     // 打开成功
    //     console.log("跳转小程序成功！", res);
    //   }
    // })
    //增加点击量
    this.addClickNumber();
    wx.redirectTo({
      url: '/pages/lifeService/managementFee/invite',
    })
  },
  go4() {
    // app.showTip("功能即将开放 敬请期待");
    //增加点击量
    this.addClickNumber();
    wx.navigateTo({
      url: '/pages/lifeService/managementFee/quick',
    })
  },
  go5(){
    wx.navigateToMiniProgram({
      appId: 'wx09df719a551e8820',
      path: 'property/pages/suggestion/suggestion',
      //develop开发版；trial体验版；release正式版
      envVersion: 'release',
      success(res) {
        // 打开成功
        console.log("跳转小程序成功！", res);
      }
    })
  },
  go6(){
    wx.navigateToMiniProgram({
      appId: 'wx09df719a551e8820',
      path: 'property/pages/questionnaire/questionnaire',
      //develop开发版；trial体验版；release正式版
      envVersion: 'release',
      success(res) {
        // 打开成功
        console.log("跳转小程序成功！", res);
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this;

    var openid = wx.getStorageSync('ly24_openid');
    // var openid='oZYOb4jQ1cdq3ZdTqRcQX4r_BI5Y'
    if (openid == '') {
      //缓存中没有openid
      //获取所需页面信息
      wx.login({
        success: function (res) {
          if (res.code) {
            //发起网络请求
            wx.request({
              url: that.data.baseUrl + 'getOpenid.php',
              method: 'POST',
              data: {
                'code': res.code
              },
              header: {
                'content-type': 'application/x-www-form-urlencoded'
              },
              success: function (res) {
                //缓存微信openid
                wx.setStorageSync('ly24_openid', res.data.openid);
                that.setData({
                  openid: res.data.openid
                });

                //获取本页数据
                that.getLifeServiceIndexPageInfo(res.data.openid);
              },
              fail: function (res) {}
            });
          }
        }
      });
    } else {
      that.setData({
        openid: openid
      });

      //获取本页数据
      that.getLifeServiceIndexPageInfo(openid);
    }

    //调用分享
    that.getShareInfo();
  },

  //获取本页数据
  getLifeServiceIndexPageInfo(openid) {
    var that = this;
    wx.showLoading({
      title: '数据加载中...'
    })
    wx.request({
      url: that.data.baseUrl + 'getLifeServiceIndexPageInfo.php',
      method: 'POST',
      data: {
        'openid': openid
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        wx.hideLoading();
        if (res.data.status == 1) {
          //重新赋值后台请求数据
          that.setData({
            mySf: res.data.mySf
          });
        } else {
          app.showTip(res.data.msg);
          setTimeout(function () {
            wx.navigateBack({
              delta: 1
            });
          }, 2000);
        }
      },
      fail: function () {
        wx.hideLoading();
        app.showTip('抱歉,服务器繁忙');
        setTimeout(function () {
          wx.navigateBack({
            delta: 1
          });
        }, 2000);
      }
    });
  },


  //获取微信分享信息
  getShareInfo() {
    var that = this;
    wx.request({
      url: that.data.baseUrl + 'getShareInfo.php',
      method: 'POST',
      data: {
        id: 28
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        that.setData({
          shareTitle: res.data.shareTitle,
          shareImg: res.data.shareImg
        });
      },
      fail: function (res) {}
    });
  },

  //增加点击量统计
  addClickNumber() {
    var that = this;
    wx.request({
      url: that.data.baseUrl + 'getShareInfo.php',
      method: 'POST',
      data: {
        pid: 9
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
       
      },
      fail: function (res) {}
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    var that = this;
    return {
      title: that.data.shareTitle,
      path: '/pages/lifeService/index',
      imageUrl: that.data.shareImg,
      success: function (res) {

      },
      fail: function (res) {

      }
    }
  }
})